# -*- coding: utf-8 -*-
N=int(raw_input())
md = {}
while(N>0):
    inputs=raw_input().split(' ')
    zhunkaozhengId = inputs[0]
    shijiId = inputs[1]
    kaoshiId = inputs[2]
    md[shijiId]=(zhunkaozhengId, kaoshiId)
    N-=1

M=int(raw_input())
shijiIds = raw_input().split(' ')
for e in shijiIds:
    print md[e][0]+' '+md[e][1]